home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Embed / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  6.2 KB  |  233 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef BINDING_K
  19. #include "Binding.k"
  20. #endif
  21.  
  22. #ifndef DEFINES_K
  23. #include "Defines.k"
  24. #endif
  25.  
  26. #ifndef SELECT_H
  27. #include "Select.h"
  28. #endif
  29.  
  30. #ifndef PROXY_H
  31. #include "Proxy.h"
  32. #endif
  33.  
  34. #ifndef FRAME_H
  35. #include "Frame.h"
  36. #endif
  37.  
  38. #ifndef CONTENT_H
  39. #include "Content.h"
  40. #endif
  41.  
  42. // ----- ODF -----
  43.  
  44. #ifndef FWABOUT_H
  45. #include "FWAbout.h"
  46. #endif
  47.  
  48. #ifndef FWMENUS_K
  49. #include "FWMenus.k"
  50. #endif
  51.  
  52. #ifndef FWSUSINK_H
  53. #include "FWSUSink.h"
  54. #endif
  55.  
  56. #ifndef FWCFMRES_H
  57. #include "FWCFMRes.h"
  58. #endif
  59.  
  60. #ifndef FWMNUBAR_H
  61. #include "FWMnuBar.h"
  62. #endif
  63.  
  64. // ----- OpenDoc Includes -----
  65.  
  66. #ifndef SOM_Module_OpenDoc_Commands_defined
  67. #include <CmdDefs.xh>
  68. #endif
  69.  
  70. #ifndef SOM_Module_OpenDoc_StdProps_defined
  71. #include <StdProps.xh>
  72. #endif
  73.  
  74. //========================================================================================
  75. //    Runtime information
  76. //========================================================================================
  77.  
  78. #ifdef FW_BUILD_MAC
  79. #pragma segment odfembed
  80. #endif
  81.  
  82. FW_DEFINE_AUTO(CEmbedPart)
  83.  
  84. //========================================================================================
  85. //    CLASS CEmbedPart
  86. //========================================================================================
  87.  
  88. #define kMainPresentation "Apple:Presentation:EmbedPart"
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //     CEmbedPart constructor
  92. //----------------------------------------------------------------------------------------
  93.  
  94. CEmbedPart::CEmbedPart(ODPart* odPart):
  95.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  96.     fPresentation(NULL),
  97.     fEmbedContent(NULL)
  98. {
  99.     // Do not call anything that can fail
  100.     FW_END_CONSTRUCTOR
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //     CEmbedPart::Initialize
  105. //----------------------------------------------------------------------------------------
  106.  
  107. void CEmbedPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  108. {
  109.     FW_CEmbeddingPart::Initialize(ev, storageUnit, fromStorage);
  110.  
  111.     // Create the presentation and selection objects.
  112.     // The selection object is actually owned by the presentation
  113.     CEmbedSelection* selection = FW_NEW(CEmbedSelection, (ev, fEmbedContent));
  114.     fPresentation = RegisterPresentation(ev, kMainPresentation, true, selection);
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //     CEmbedPart destructor
  119. //----------------------------------------------------------------------------------------
  120.  
  121. CEmbedPart::~CEmbedPart()
  122. {
  123.     FW_START_DESTRUCTOR
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    CEmbedPart::NewPartContent
  128. //----------------------------------------------------------------------------------------
  129.  
  130. FW_CContent* CEmbedPart::NewPartContent(Environment* ev)
  131. {
  132.     fEmbedContent = FW_NEW(CEmbedContent, (ev, this));
  133.     return fEmbedContent;
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //     CEmbedPart::NewFrame
  138. //----------------------------------------------------------------------------------------
  139.  
  140. FW_CFrame* CEmbedPart::NewFrame(Environment* ev, 
  141.                                 ODFrame* odFrame, 
  142.                                 FW_CPresentation* presentation, 
  143.                                 FW_Boolean fromStorage)
  144. {
  145. FW_UNUSED(presentation);
  146. FW_UNUSED(fromStorage);
  147.     
  148.     return FW_NEW(CEmbedFrame, (ev, odFrame, presentation, this, fEmbedContent));
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. // CEmbedPart::DoAdjustMenus
  153. //----------------------------------------------------------------------------------------
  154.  
  155. FW_Handled CEmbedPart::DoAdjustMenus(Environment* ev, 
  156.                                     FW_CMenuBar* menuBar, 
  157.                                     FW_Boolean hasMenuFocus,
  158.                                     FW_Boolean isRoot)
  159. {
  160. FW_UNUSED(isRoot);
  161.     if (hasMenuFocus)
  162.     {
  163.         FW_Boolean hasProxy = (fEmbedContent->GetProxy() != NULL);
  164.         FW_Boolean oneFacet = (GetFacetNumberCommandID() == cOneFacet);
  165.         
  166.         menuBar->EnableAndCheckCommand(ev, cOneFacet, hasProxy, oneFacet);
  167.         menuBar->EnableAndCheckCommand(ev, cFourFacets, hasProxy, !oneFacet);
  168.         menuBar->EnableAndCheckCommand(ev, cRotateFacets, !oneFacet && (fEmbedContent->GetProxy() != NULL), false);
  169.     }
  170.     
  171.     return FW_kNotHandled;
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. // CEmbedPart::DoMenu
  176. //----------------------------------------------------------------------------------------
  177.  
  178. FW_Handled CEmbedPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  179. {
  180.     FW_Handled menuHandled = FW_kHandled;
  181.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  182.     
  183.     switch (id)
  184.     {
  185.         case cOneFacet:
  186.         case cFourFacets:
  187.             if (GetFacetNumberCommandID() != id)
  188.             {
  189.                 fEmbedContent->ChangeFacetNumber(ev, id == cOneFacet ? 1 : 4);    
  190.                 fPresentation->Invalidate(ev);
  191.             }
  192.             break;
  193.         
  194.         case cRotateFacets:
  195.             fEmbedContent->Rotate(ev);        
  196.             break;
  197.             
  198.         default:
  199.             menuHandled = FW_kNotHandled;
  200.     }
  201.     
  202.     return menuHandled;
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    CEmbedPart::DoAbout
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_Handled CEmbedPart::DoAbout(Environment* ev)
  210. {
  211.     ::FW_About(ev, this, kAbout);
  212.     
  213.     return FW_kHandled;
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //     CEmbedPart::GetRotation
  218. //----------------------------------------------------------------------------------------
  219.  
  220. short CEmbedPart::GetRotation() const
  221. {
  222.     return fEmbedContent->GetRotation();
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //     CEmbedPart::GetFacetNumberCommandID
  227. //----------------------------------------------------------------------------------------
  228.  
  229. ODCommandID CEmbedPart::GetFacetNumberCommandID() const
  230. {
  231.     return (fEmbedContent->GetFacetNumber() == 1) ? cOneFacet : cFourFacets;
  232. }
  233.